package com.example.demo.model;

import com.baidu.bas.annotation.Erupt;
import com.baidu.bas.annotation.EruptField;
import com.baidu.bas.annotation.config.QueryExpression;
import com.baidu.bas.annotation.sub_field.Edit;
import com.baidu.bas.annotation.sub_field.EditType;
import com.baidu.bas.annotation.sub_field.Searchable;
import com.baidu.bas.annotation.sub_field.View;
import com.baidu.bas.annotation.sub_field.sub_edit.Search;
import com.baidu.bas.upms.model.base.HyperModel;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.List;

/**
 * 微信模板[保留所有记录]. 支持手工+自动 同步
 * 每次都新增记录,保存历史同步信息. 用时取最新的记录
 * @author liuzhenchuan@foxmail.com
 * @date 2020/12/22
 */
@Getter
@Setter
@Erupt(name = "微信模板",orderBy = "id desc")
@Table(name = "ma_wechat_tempalte")
@Entity
@TypeDef(name = "json", typeClass = JsonStringType.class)
public class WechatTemplate extends HyperModel {

    @Column(name = "content", columnDefinition = "json")
    @Type(type = "json")
    @EruptField(
            views = @View(title = "模板内容"),
            edit = @Edit(title = "模板内容",type = EditType.HIDDEN)
    )
    private List<WxMpTemplate> content;

    @ManyToOne
    @EruptField(
            views = {
                    @View(title = "ID", column = "id"),
                    @View(title = "账号", column = "name")
            },
            edit = @Edit(title = "账号", type = EditType.REFERENCE_TABLE, search = @Search),
            searchable = @Searchable(omitBlank = true,permitOperation = {QueryExpression.in,QueryExpression.EQ})
    )
    private Account account;


}
